﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ent;
namespace DAL
{
    public class DapAnDAL:clsKetNoi
    {
        dataDataContext dt;
        public int TongSoDapAnDung(string macauhoi)
        {
            dt = GetKetnoi();
            IEnumerable<DAPAN> ds = dt.DAPANs.Where(k => k.MACAUHOI == macauhoi).Where(j => j.LOAIDA == 1);
            return ds.Count();
        }
        public bool Traloi(string Macauhoi, List<TraLoiThi> ds)
        {
            dt = GetKetnoi();
            IEnumerable<DAPAN> dsdapan = dt.DAPANs.Where(k => k.MACAUHOI == Macauhoi);
            int x = 0;
            int y = 0;
            foreach (DAPAN item in dsdapan)
            {
                foreach (TraLoiThi tl in ds)
                {
                    if (tl.MaDapAn == item.MADAPAN && tl.LoaiDA == int.Parse(item.LOAIDA.ToString()))
                    {
                        x++;
                    }
                }
                y++;
            }
            if (x == y) return true;
            else return false;
        }
        public List<TraLoiThi> DanhsachDapAn_Thi(string MaCauHoi)
        {
            dt = GetKetnoi();
            IEnumerable<DAPAN> ds = dt.DAPANs.Where(j => j.MACAUHOI == MaCauHoi);
            List<TraLoiThi> DsDapAn = new List<TraLoiThi>();
            foreach (DAPAN item in ds)
            {
                TraLoiThi DapAn = new TraLoiThi();
                DapAn.MaCauHoi = MaCauHoi;
                DapAn.HinhAnh = item.HINHANH;
                DapAn.LoaiDA = 0;
                DapAn.MaDapAn = item.MADAPAN;
                DapAn.NoiDung = item.NOIDUNG;
                DsDapAn.Add(DapAn);
            }
            return DsDapAn;
        }
    }
}
